package org.adream.account.service;

import org.adream.account.aop.annotation.DataSource;
import org.adream.account.dao.Dream2020UserDao;
import org.adream.account.entity.Dream2020UserEntity;
import org.adream.account.model.ResultModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 新版盒子用户service
 * @author sl
 *
 */
@Service
@DataSource("adreambox2020DataSource")
public class Dream2020UserService {
	
	@Autowired
	private Dream2020UserDao dream2020UserDao;
	
	private final static Logger logger = LoggerFactory.getLogger(Dream2020UserService.class);
	
	/**
	 * 查询用户梦想课时数
	 * @param uid
	 * @return
	 */
	public ResultModel<Integer> queryDream2020UserCourseTimeNumByCasId(String uid) {
		Dream2020UserEntity dream2020User = dream2020UserDao.queryDream2020UserCourseTimeNumByCasId(uid);
		if(dream2020User == null) {
			logger.warn("用户梦想课时数不存在:(");
			return new ResultModel<Integer>(ResultModel.NOT_FOUND_OBJECT, "查询失败,数据不存在", 0);
		}
		return new ResultModel<Integer>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, dream2020User.getCourseTimeNum());
	}
	
	/**
	 * 查询用户开课记录数
	 * @param uid
	 * @param ts
	 * @return
	 */
	public ResultModel<Integer> queryDream2020UserSetUpCourseNumByCasId(String uid, Long ts) {
		Dream2020UserEntity dream2020User = dream2020UserDao.queryDream2020UserSetUpCourseNumByCasId(uid, ts);
		if(dream2020User == null) {
			logger.warn("用户开课记录数不存在:(");
			return new ResultModel<Integer>(ResultModel.NOT_FOUND_OBJECT, "查询失败,数据不存在", 0);
		}
		return new ResultModel<Integer>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, dream2020User.getSetUpCourseNum());
	}
}